package com.health.adapter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.health.R;
import com.health.tablebean.BD_DD_INFO;
import com.health.tools.GlobalConts;

import android.annotation.SuppressLint;
import android.content.Context;
import android.text.InputType;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.TextView;

/**
 * 修复bug
 * 
 * @author 鹿云龙
 */
public class CheckBoxAdapter extends BaseAdapter {
	private static int iotherLength = -1;// otherEditText限制字数长度
	private List<BD_DD_INFO> list;
	private List<CheckViewHolder> holderList;
	private BD_DD_INFO tempGridViewItem;
	private LayoutInflater layoutInflater;
	private EditText editText;
	private HashMap<Integer, CheckViewHolder> checkMap;
	public CheckBox checkBox;
	private boolean otherVis = true;
	private boolean otherVisSelect = false;

	public void setOtherVis(boolean otherVis) {
		otherVisSelect = true;
		this.otherVis = otherVis;
		if (editText != null) {

			if (otherVis) {
				editText.setText("");
				editText.setVisibility(View.VISIBLE);
			} else {
				editText.setVisibility(View.GONE);
			}
		}
	}

	/**
	 * otherEditText限制字数长度
	 */
	public void setOtherMaxLength(int iotherLength) {
		this.iotherLength = iotherLength;
	}

	/**
	 * 设置选中的CheckBox
	 */
	private List<BD_DD_INFO> checkedList;
	private List<String> checkedCodeList;
	private int mtextSize;
	private int mtextColor;
	private boolean textsizech;
	private boolean textcolorch;
	private boolean canCheck = true;
	private boolean danxuan = false;

	private Map<String, Integer> otherLength;
	private int otherTextMaxLength = noOtherMaxLength;
	private static final int noOtherMaxLength = 1000;

	/**
	 * 
	 * @param lengthMap<EditText.getText,MaxLength>
	 */
	public void setOtherMaxLength(Map<String, Integer> lengthMap) {
		this.otherLength = lengthMap;
	}

	// public void refOtherText() {
	// try {
	// if (editText != null) {
	// editText.setText(m_other);
	// }
	// Object[] keys = checkMap.keySet().toArray();
	// int[] n = new int[keys.length];
	// for (int i = 0; i < keys.length; i++) {
	// n[i] = (int) keys[i];
	// }
	// for (int key : n) {
	// CheckViewHolder cvh = ((CheckViewHolder) checkMap.get(key));
	// String str = cvh.cbIamge.getText().toString();
	// if (str.equals("其他") || str.equals("12其他") || str.equals("10其他")) {
	// System.out.println(str);
	// cvh.otherText.setText(m_other);
	// }
	// }
	// } catch (Exception e) {
	// e.printStackTrace();
	// }
	// }

	/**
	 * 需要显示文本框的选项
	 * 
	 * 6.其他-----老年人 （中医体质辨识）
	 */
	private String[] visOther = new String[] { "其他", "减体重", "建议接种疫苗", "10 其他", "12其他", "其他遗传代谢病", "6.其他" };//
	/**
	 * 需要隐藏文本框并清空选项禁止选择其他选项的选项，通常item=0
	 */
	private String[] invisOther = new String[] { "未见异常", "无症状", "未发现", "1 无症状", "无" ,"正常","没有症状"};

	private boolean contains(String[] valueArr, String targetValue) {
		return Arrays.asList(valueArr).contains(targetValue);
	}

	/**
	 * 在布局初始化时会创建多个第一个position= 0的CheckViewHolder对象,
	 * 如果只对单个对象进行操作会导致操作无效，所以把所有产生的position= 0的对象放到一个list中，操作时修改list中所有对象
	 */
	boolean ballLoad;// 加载完所有的CheckBox

	public void danxuan(boolean dx) {
		danxuan = dx;
	}

	public void clear() {
		Object[] keys = checkMap.keySet().toArray();
		if (keys.length != 0) {
			for (int i = 0; i < checkMap.size(); i++) {
				CheckViewHolder cvh = (CheckViewHolder) checkMap.get((int) keys[i]);
				cvh.cbIamge.setChecked(false);
				cvh.cbIamge.setClickable(false);
			}
		}
		this.notifyDataSetChanged();
	}

	public void canChecked(boolean check) {
		this.canCheck = check;
		if (getOtherTextView() != null) {
			if (canCheck) {
				getOtherTextView().setEnabled(true);
			} else {
				getOtherTextView().setText("");
				getOtherTextView().setEnabled(false);
			}
		}
	}

	@SuppressLint("UseSparseArrays")
	public CheckBoxAdapter(Context context, List<BD_DD_INFO> list, EditText edittext) {
		this.list = list;
		layoutInflater = LayoutInflater.from(context);
		checkMap = new HashMap<Integer, CheckViewHolder>();
		holderList = new ArrayList<>();

		this.editText = edittext;
		closeText(editText);
	}

	/**
	 * 禁用EditText并清空文字
	 * 
	 * @param et
	 * @author 鹿云龙
	 * @date 2016年5月9日 上午9:14:11
	 */
	private void closeText(EditText et) {
		if (et != null) {
			et.setText("");
			// m_other="";
			et.setEnabled(false);
			et.setFocusable(false);
			et.setFocusableInTouchMode(false);
			et.setClickable(false);
		}
	}

	@SuppressLint("UseSparseArrays")
	public CheckBoxAdapter(Context context, List<BD_DD_INFO> list) {
		this.list = list;
		layoutInflater = LayoutInflater.from(context);
		checkMap = new HashMap<Integer, CheckViewHolder>();
		holderList = new ArrayList<>();
	}

	public void setCheckedCodeList(List<String> checkedCodeList) {
		this.checkedCodeList = checkedCodeList;
		notifyDataSetChanged();
	}

	/**
	 * 数据总数
	 */
	@Override
	public int getCount() {
		return list.size();
	}

	/**
	 * 获取当前数据
	 */
	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressLint({ "ViewHolder", "InflateParams" })
	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		View view;
		Log.i("ttttt", position + "");
		view = layoutInflater.inflate(R.layout.checkboxitem, null);
		Log.i("ttttt", parent.getChildCount() + "    " + position);
		if (parent.getChildCount() == position) {
			try {
				if (layoutInflater != null) {
					CheckBox cb = (CheckBox) view.findViewById(R.id.checkBox);
					EditText et = (EditText) view.findViewById(R.id.othertext);
					// 获取自定义的类实例
					tempGridViewItem = list.get(position);
					CheckViewHolder avh = new CheckViewHolder();
					avh.weight1 = (TextView) view.findViewById(R.id.weight1);
					avh.weight2 = (TextView) view.findViewById(R.id.weight2);
					avh.cbIamge = cb;
					avh.choseView = view;
					avh.otherText = et;// 输出查看text
					avh.dd_info = tempGridViewItem;
					if (otherVisSelect) {
						if (editText != null) {
							if (otherVis) {
								editText.setVisibility(View.VISIBLE);
							} else {
								editText.setText("");
								editText.setVisibility(View.GONE);
							}
						}
					}
					if (contains(visOther, tempGridViewItem.getDATAINFO())) {
						if (editText != null) {
							avh.otherText.setVisibility(View.GONE);
						} else {
							avh.otherText.setVisibility(View.VISIBLE);
							// avh.otherText.setText("asdasd");
							if (m_other != null) {
								avh.otherText.setText(m_other);
							}
							if ("减体重".equals(tempGridViewItem.getDATAINFO())) {
								avh.weight1.setVisibility(View.VISIBLE);
								avh.weight2.setVisibility(View.VISIBLE);
								avh.otherText
										.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
							}
							if (otherLength != null) {
								if (otherLength.containsKey(avh.otherText.getText())) {
									GlobalConts.setMaxLength(otherLength.get(avh.otherText.getText()), avh.otherText);
								}

							}
						}

						if (iotherLength != -1) {
							GlobalConts.setMaxLength(iotherLength, avh.otherText);
						}
						if (avh.cbIamge.isChecked()) {
							if (editText != null) {
								openEditText(editText, m_other);
							} else {
								openEditText(avh.otherText, m_other);
							}
							// TODO
						} else {
							closeText(avh.otherText);
						}
						// avh.otherText.setText(m);

					}
					if (textsizech) {
						avh.cbIamge.setTextSize(mtextSize);
					}
					if (textcolorch) {
						avh.cbIamge.setTextColor(mtextColor);
					}

					cb.setOnCheckedChangeListener(new OnCheckedChangeListenerImpl(avh, position));

					cb.setFocusable(false);
					cb.setText(tempGridViewItem.getDATAINFO());

					if (checkedList != null && checkedList.size() > 0) {
						for (BD_DD_INFO info : checkedList) {
							if (avh.cbIamge.getText().toString().equals(info.getDATAINFO())) {
								avh.cbIamge.setChecked(true);
							}
						}
					}

					if (checkedCodeList != null && checkedCodeList.size() > 0) {
						for (String str : checkedCodeList) {
							if (avh.cbIamge.getText().toString().equals(getNameByCode(str))) {
								avh.cbIamge.setChecked(true);
							}
						}
					}
					if (contains(visOther, tempGridViewItem.getDATAINFO())) {
						
						if (avh.cbIamge.isChecked()) {
							if (editText != null) {
								openEditText(editText, m_other);
							} else {
								openEditText(avh.otherText, m_other);
							}
							// TODO
						} else {
							closeText(avh.otherText);
						}
						// avh.otherText.setText(m);

					}
					if (checkMap.size() == list.size()) {
						ballLoad = true;

					}
					Log.i("ttttt", this + "  " + avh.cbIamge.getText().toString());

					checkMap.put(position, avh);
					holderList.add(avh);
					setChecked(chekedsStr);
					// setOther(other);
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return view;
	}

	final class CheckViewHolder {
		CheckBox cbIamge;
		View choseView;
		EditText otherText;
		BD_DD_INFO dd_info;
		TextView weight1;
		TextView weight2;
	}

	private String getNameByCode(String code) {
		for (BD_DD_INFO info : list) {
			if (code.equals(info.getID())) {
				return info.getDATAINFO();
			}
		}
		return null;
	}

	private String chekedsStr;

	/**
	 * 设置选中项
	 * 
	 * @param checkeds
	 *            选中对象的id,以英文逗号分隔(例："DM_001,DM_002,DM_003...")
	 * @author 鹿云龙
	 * @date 2015年12月21日 上午9:36:49
	 */
	public void setChecked(String checkeds) {
		if (ballLoad) {
			return;
		}
		chekedsStr = checkeds;
		if (checkeds == null || checkeds.equals("")) {
			return;
		}
		if (checkMap.size() == 0) {
			for (int i = 0; i < holderList.size(); i++) {
				checkMap.put(i, holderList.get(i));
			}
		}
		String[] cks = checkeds.split(",");
		Object[] keys = checkMap.keySet().toArray();

		for (int i = 0; i < checkMap.size(); i++) {
			CheckViewHolder cvh = (CheckViewHolder) checkMap.get((int) keys[i]);
			for (String ck : cks) {
				if (ck.equals("DM01-25_6")) {
					System.out.println("");
				}
				if (contains(visOther, cvh.dd_info.getDATAINFO())) {
					openEditText(cvh.otherText, "");
					// cvh.otherText.setVisibility(View.VISIBLE);
					// closeText(cvh.otherText);
				}
				if (cvh.dd_info.getID().equals(ck)) {
					if (contains(invisOther, cvh.dd_info.getDATAINFO())) {
						setWuZhengZhuangChecked(true);
					}
					Log.i("ttttt", cvh.dd_info.getID() + " length: " + checkMap.size());

					cvh.cbIamge.setChecked(true);
					if (cvh.dd_info.getDATAINFO().equals("减体重")) {
						cvh.otherText.setText(mAIM);
					}
					if (cvh.dd_info.getDATAINFO().equals("建议接种疫苗")) {
						cvh.otherText.setText(mADVICE);
					}
				}
			}
		}

	}

	/**
	 * size The scaled pixel size.
	 * 
	 * @param size
	 * @author 鹿云龙
	 * @date 2015年12月18日 下午2:36:29
	 */
	public void setTextSize(int textSize) {
		this.mtextSize = textSize;
		textsizech = true;
	}

	/**
	 * Sets the text color.
	 * 
	 * @param colors
	 * @author 鹿云龙
	 * @date 2015年12月18日 下午2:36:36
	 */
	public void setTextColor(int textColors) {
		this.mtextColor = textColors;
		textcolorch = true;
	}

	/**
	 * 获取选中对象的SORT
	 * 
	 * @return
	 * @author 鹿云龙
	 * @date 2015年12月17日 上午11:16:44
	 */
	public ArrayList<String> getCheckedIds() {
		ArrayList<String> str = new ArrayList<String>();
		// checkBD_DD_INFOs.clear();
		Object[] keys = checkMap.keySet().toArray();
		for (int i = 0; i < checkMap.size(); i++) {
			CheckViewHolder cvh = (CheckViewHolder) checkMap.get((int) keys[i]);
			str.add(cvh.dd_info.getID());

		}
		return str;
	}

	/**
	 * 获取选中对象的SORT
	 * 
	 * @return
	 * @author 鹿云龙
	 * @date 2015年12月17日 上午11:16:44
	 */
	public String getCheckedSorts() {
		String str = "";
		Object[] keys = checkMap.keySet().toArray();
		if (keys.length != 0) {
			for (int i = 0; i < checkMap.size(); i++) {
				CheckViewHolder cvh = (CheckViewHolder) checkMap.get((int) keys[i]);

				if (cvh.cbIamge.isChecked()) {
					str += cvh.dd_info.getSORT() + ",";
				}
			}
			if (str.length() != 0) {
				str = str.substring(0, str.length() - 1);
			}
		}
		return str;
	}

	/**
	 * 获取选中对象的id ,使用英文逗号隔开
	 * 
	 * @return 1,2,3...
	 * @author 鹿云龙
	 * @date 2015年12月17日 上午11:16:44
	 */
	public String getCheckedIdsStr() {
		String str = "";
		Object[] keys = checkMap.keySet().toArray();
		if (keys.length != 0) {
			for (int i = 0; i < checkMap.size(); i++) {
				CheckViewHolder cvh = (CheckViewHolder) checkMap.get((int) keys[i]);

				if (cvh.cbIamge.isChecked()) {
					str += cvh.dd_info.getID() + ",";
				}
			}
			if (str.length() != 0) {
				str = str.substring(0, str.length() - 1);
			}
		}
		return str;
	}

	/**
	 * 获取选中的BD_DD_INFO对象
	 * 
	 * @return
	 * @author 鹿云龙
	 * @date 2015年12月17日 上午11:16:53
	 */
	public ArrayList<BD_DD_INFO> getCheckedBD_DD_INFO() {
		ArrayList<BD_DD_INFO> arr = new ArrayList<BD_DD_INFO>();
		Object[] keys = checkMap.keySet().toArray();
		for (int i = 0; i < checkMap.size(); i++) {
			CheckViewHolder cvh = (CheckViewHolder) checkMap.get((int) keys[i]);
			if (cvh.cbIamge.isChecked()) {
				arr.add(cvh.dd_info);
			}
		}
		return arr;
	}

	boolean wuzhengzhuangIsChecked;

	public void setWuZhengZhuangChecked(boolean checked) {
		this.wuzhengzhuangIsChecked = checked;
	}

	private String m_other;
	private String mAIM;// 减体重
	private String mADVICE;// 建议接种疫苗

	public void setAIM(String aim) {
		mAIM = aim;
	}

	public void setADVICE(String advice) {
		mADVICE = advice;
	}

	/**
	 * 设置其他数据
	 * 
	 * @param other
	 * @author 鹿云龙
	 * @date 2015年12月21日 下午2:02:32
	 */
	public void setOther(String other) {
		this.m_other = other;
		try {
			if (editText != null) {
				editText.setText(m_other);
			}
			Object[] keys = checkMap.keySet().toArray();
			int[] n = new int[keys.length];
			for (int i = 0; i < keys.length; i++) {
				n[i] = (int) keys[i];
			}
			for (int key : n) {
				CheckViewHolder cvh = ((CheckViewHolder) checkMap.get(key));
				String str = cvh.cbIamge.getText().toString();
				// if (str.equals("其他") || str.equals("12其他") ||
				// str.equals("10其他")) {
				// System.out.println(str);
				// cvh.otherText.setText(m_other);
				// }

				if (contains(visOther, str)) {
					System.out.println(str);
					cvh.otherText.setText(m_other);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 获取其他数据
	 * 
	 * @return
	 * @author 鹿云龙
	 * @date 2015年12月21日 上午9:25:41
	 */
	public String getOther() {
		String other = "";
		try {
			if (editText != null) {
				return editText.getText().toString();
			}
			Object[] keys = checkMap.keySet().toArray();
			int[] n = new int[keys.length];
			for (int i = 0; i < keys.length; i++) {
				n[i] = (int) keys[i];
			}
			for (int key : n) {
				CheckViewHolder cvh = ((CheckViewHolder) checkMap.get(key));
				String str = cvh.cbIamge.getText().toString();
				if (str.equals("产前筛查宣传告知")) {
					System.out.println("");
				}
				if (str.equals("营养")) {
					System.out.println("");
				}
				// if (str.equals("其他") || str.equals("12其他") ||
				// str.equals("10其他")) {
				// System.out.println(str);
				// other = cvh.otherText.getText().toString();
				// }

				if (contains(visOther, str)) {// other
					System.out.println(str);
					other = cvh.otherText.getText().toString();
				}
			}
			return other;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return other;
	}

	/**
	 * 获取其他数据EditText
	 * 
	 * @return
	 * @author 鹿云龙
	 * @date 2015年12月21日 上午9:25:41
	 */
	private EditText getOtherTextView() {
		EditText other = null;
		try {
			if (editText != null) {
				return editText;
			}
			Object[] keys = checkMap.keySet().toArray();
			int[] n = new int[keys.length];
			for (int i = 0; i < keys.length; i++) {
				n[i] = (int) keys[i];
			}
			for (int key : n) {
				CheckViewHolder cvh = ((CheckViewHolder) checkMap.get(key));
				String str = cvh.cbIamge.getText().toString();

				// if (str.equals("其他") || str.equals("12其他") ||
				// str.equals("10其他")) {
				// System.out.println(str);
				// other = cvh.otherText;
				// }
				if (contains(visOther, str)) {
					System.out.println(str);
					other = cvh.otherText;
				}
			}
			return other;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	/**
	 * 获取建议接种疫苗其他数据
	 * 
	 * @return
	 * @author 鹿云龙
	 * @date 2015年12月21日 上午9:25:41
	 */
	public String getADVICE() {
		String other = "";
		try {
			Object[] keys = checkMap.keySet().toArray();
			int[] n = new int[keys.length];
			for (int i = 0; i < keys.length; i++) {
				n[i] = (int) keys[i];
			}
			for (int key : n) {
				CheckViewHolder cvh = ((CheckViewHolder) checkMap.get(key));
				String str = cvh.cbIamge.getText().toString();
				if (str.equals("建议接种疫苗")) {
					System.out.println(str);
					other = cvh.otherText.getText().toString();
				}
			}
			return other;
		} catch (Exception e) {
			e.printStackTrace();
			return "";
		}
	}

	/**
	 * 获取减体重其他数据
	 * 
	 * @return
	 * @author 鹿云龙
	 * @date 2015年12月21日 上午9:25:41
	 */
	public String getAIM() {
		String other = "";
		try {
			Object[] keys = checkMap.keySet().toArray();
			int[] n = new int[keys.length];
			for (int i = 0; i < keys.length; i++) {
				n[i] = (int) keys[i];
			}
			for (int key : n) {
				CheckViewHolder cvh = ((CheckViewHolder) checkMap.get(key));
				String str = cvh.cbIamge.getText().toString();
				if (str.equals("减体重")) {
					System.out.println(str);
					other = cvh.otherText.getText().toString();
				}
			}
			return other;
		} catch (Exception e) {
			e.printStackTrace();
			return "";
		}
	}

	class OnCheckedChangeListenerImpl implements CompoundButton.OnCheckedChangeListener {
		CheckViewHolder holder;
		int position;

		public OnCheckedChangeListenerImpl(CheckViewHolder holder, int position) {
			super();
			this.holder = holder;
			this.position = position;
		}

		@Override
		public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
			try {
				if (!isChecked) {
					m_other = "";
				}
				Object[] keys = checkMap.keySet().toArray();
				CheckViewHolder cvh = ((CheckViewHolder) checkMap.get(position));
				String checkboxtext = cvh.cbIamge.getText().toString();
				System.out.println(checkboxtext);
				if (danxuan) {// 单选
					if (contains(invisOther, checkboxtext)) {
						if (isChecked) {
							wuzhengzhuangIsChecked = true;// TODO
							// unChecked();
						} else if (!isChecked) {
							wuzhengzhuangIsChecked = false;
						}
					}
					cvh.cbIamge.setChecked(isChecked);
					for (int i = 0; i < checkMap.size(); i++) {
						CheckViewHolder cvh1 = (CheckViewHolder) checkMap.get((int) keys[i]);
						if (!cvh1.cbIamge.getText().equals(cvh.dd_info.getDATAINFO()) && isChecked) {
							cvh1.cbIamge.setChecked(false);
						}
						// if (contains(visOther, cvh1.dd_info.getDATAINFO()) &&
						// cvh.dd_info.equals(cvh1.dd_info)
						// && isChecked) {
						// openEditText(cvh1.otherText, null);
						// cvh1.otherText.setText(m_other);
						// // }
						// }
						// if (contains(visOther, cvh1.dd_info.getDATAINFO()) &&
						// cvh.dd_info.equals(cvh1.dd_info)
						// && !isChecked) {
						// m_other = "";
						// closeText(cvh1.otherText);
						// }

						if (contains(visOther, checkboxtext)) {// other
							if (isChecked) {
								openEditText(cvh.otherText, null);
							} else {
								closeText(cvh.otherText);
							}
						}
					}
					return;
				}

				if (contains(invisOther, checkboxtext)) {
					if (isChecked) {
						wuzhengzhuangIsChecked = true;// TODO
						// unChecked();
					} else if (!isChecked) {
						wuzhengzhuangIsChecked = false;
					}
				}
				if (wuzhengzhuangIsChecked) {
					unChecked();
				} else {
					holder.cbIamge.setChecked(isChecked);
				}

				if (contains(visOther, checkboxtext)) {// other
					if (!wuzhengzhuangIsChecked) {
						if (isChecked) {
							openEditText(cvh.otherText, m_other);
						} else {
							openEditText(cvh.otherText, m_other);
							closeText(cvh.otherText);
						}
						if (editText != null) {// TODO 需要把editText只用自带的
							if (otherVisSelect) {
								if (!otherVis) {
									editText.setVisibility(View.GONE);
								}
							}
							if (!otherVisSelect && otherVis) {
								if (isChecked) {
									openEditText(cvh.otherText, m_other);
									openEditText(editText, m_other);
								} else {
									openEditText(cvh.otherText, m_other);
									closeText(editText);
								}
							}

						}
					}
				}

				if (contains(visOther, checkboxtext) && editText != null) {
					if (isChecked) {
						openEditText(cvh.otherText, m_other);
						// closeText(editText);
					} else {
						// openEditText(editText, null);
						closeText(editText);
					}
				}
				if (!canCheck) {
					holder.cbIamge.setChecked(false);
					m_other = "";
					closeText(editText);
					closeText(cvh.otherText);
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		/**
		 * 选中无症状后禁止选中其他项
		 * 
		 * @param keys
		 * @author 鹿云龙
		 * @date 2016年5月9日 下午1:58:37
		 */
		private void unChecked() {
			// checkMap.keySet();
			Object[] keys = checkMap.keySet().toArray();
			for (int i = 0; i < checkMap.size(); i++) {
				CheckViewHolder c = ((CheckViewHolder) checkMap.get((int) keys[i]));
				if (contains(invisOther, c.cbIamge.getText().toString())) {
					// continue;
				} else {
					((CheckViewHolder) checkMap.get((int) keys[i])).cbIamge.setChecked(false);
					if (contains(visOther, checkMap.get((int) keys[i]).dd_info.getDATAINFO())) {
						closeText(checkMap.get((int) keys[i]).otherText);
					}
				}
			}
		}
	}

	private void openEditText(EditText et, String str) {
		if (et != null) {
			if (otherVisSelect) {
				if (!otherVis) {
					et.setVisibility(View.GONE);
					return;
				}
			}
			et.setVisibility(View.VISIBLE);
			et.setEnabled(true);
			et.setFocusable(true);
			et.setFocusableInTouchMode(true);
			et.setClickable(true);
			if (!TextUtils.isEmpty(str)) {
				et.setText(str);
			}
		}
	}

}